const app = getApp()
const util = require('../../../utils/util')
Page({
	data: {
		formDate:{
		    groupUnit: "",
		    industry: "",
		    industryManager: '',
		    money: "",
		    name: "",
		    notes: "",
			projectNode:{
		        bidTime: "",
		        biddingTime: "",
		        buildTeam: '',
		        communicate: "",
		        fieldResearch: "",
		        initiateTime: "",
		        needSupport: "",
		        notes: "",
		        obtainTime: "",
		        obtainWay: "",
		        progress: "",
		        statusSummary: "",
		        visit: ""
		    }
		},
		ryList:[],
		show: false,
		item:'',
		team:[
			{name:'是',id:1},
			{name:'否',id:0}
		],
		teamid:'',
		baseUrl: app.globalData.baseUrl,
		shenpi:[]
	},
	onLoad(options) {
		var list=[]
		wx.getStorageSync('ryList').forEach(a => {
			if(a.position==6){
				list.push({nickname:a.nickname,id:a.id,avatar:a.avatar})
			}
		});
		this.setData({
			ryList:list
		})
		this.ready()
	},
	ready(){
		app.indexApi.shenpi().then(a => {
			if (a.code == 0) {
			  this.setData({
				shenpi:a.data
			  })
			}
		})
	},
	submit(){
		app.indexApi.productSubMit(this.data.formDate).then(a => {
			if (a.code == 0) {
				wx.showToast({
					title: '提交成功', //提示的内容
					icon: 'none', //图标有success、error、loading、none四种
				 })
				 setTimeout(function(){
					wx.navigateTo({
						url: '/pages/project/list/view?id='+a.data
					})
				 },1000)
			}
		})
	},
	selectType(e) {
		let key = e.detail.value;
		var id=this.data.ryList[key].id
		this.data.formDate.industryManager=id
		var str={
			group:'行业经理',
			users:[this.data.ryList[key]]
		}
		this.data.shenpi.splice(this.data.shenpi.length-1, 0,str)
    	this.setData({
			pid: key,
			formDate:this.data.formDate,
			shenpi:this.data.shenpi
		})
	  },
	  teamType(e) {
		let key = e.detail.value;
		this.data.formDate.projectNode.buildTeam=this.data.team[key].id
    	this.setData({
			teamid: key,
			formDate:this.data.formDate
		})
	  },
	  showPicker (e) {
		let item = e.target.dataset.item;
		this.setData({
		  show: true,
		  item:item
		})
	  },
	  changeA(){
		this.setData({
			show: false
		})  
	  },
	  handleChange (e) {
		// 选择器所抛出的结果
		const timestamp = e.detail.value
		this.data.formDate.projectNode[this.data.item]=util.formatTime(timestamp, '{y}-{m}-{d} {h}:{i}')
		this.setData({
			show: false,
			formDate: this.data.formDate
		})
	  },
	bindinput(e) {
		let item = e.target.dataset.item;
		let itemdd=e.target.dataset.dd;
		const array = this.data.formDate;
		if(itemdd){
			array[item][itemdd] = e.detail.value; 
		}else{
			array[item] = e.detail.value;
		}
		this.setData({ formDate: array });
		console.log(this.data.formDate)
	},
})